package pharao.client.views.game.landkarte.ort.training;

import java.util.List;

import pharao.client.views.events.GetModelDataEvent;
import pharao.client.views.events.SetModelDataEvent;
import pharao.client.views.game.landkarte.ort.training.events.SetTrainingLessonsEvent;
import hmvc4gwt.client.event.IHmvcEvent;
import hmvc4gwt.framework.client.model.GuiModel;

public class TrainingModel extends GuiModel {
	
	private Training training;

	public void init() {
		
		getController().register(GetModelDataEvent.class, this);
		getController().register(SetTrainingLessonsEvent.class, this);
		
	}

	public void terminate() {
		// TODO Auto-generated method stub

	}

	public void handleEvent(IHmvcEvent event) {
		
		if (event instanceof GetModelDataEvent) {
			getController().fireEventLocal(new SetModelDataEvent(getTraining()));
		} else if (event instanceof SetTrainingLessonsEvent) {
			addTraining((List) event.getPayload());
		}
	}

	private void addTraining(List listLessons) {
		setTraining(new Training(listLessons));
		getController().fireEventLocal(new SetModelDataEvent(getTraining()));
	}

	private Training getTraining() {
		return training;
	}

	private void setTraining(Training training) {
		this.training = training;
	}

}
